package com.marktotop.demo;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

/**
 * @author WXLD
 * @data 2021/4/29 - 14:10
 */
public class ComplexTable extends JTable {
    // 标识单元格是否要被横向合并
    public final static Object mergeCellX = "mergeCellX";
    // 标识单元格是否要被纵向合并
    public final static Object mergeCellY = "mergeCellY";

    public ComplexTable(Object[][] headerRows , Object[][] body){
        super( new DefaultTableModel(body, headerRows[0]) );
//        this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        // 设置table内容居中
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        tcr.setHorizontalAlignment(JLabel.CENTER);
        this.setDefaultRenderer(Object.class, tcr);
        this.setRowHeight(24);
        this.setFont(new Font("Menu.font", Font.BOLD, 15));

        //TODO: 扩展body的合并

        // 设置表头UI
        this.getTableHeader().setUI(new ComplexTableHeader(headerRows , this));
    }
}
